package com.manor.paradise.adapter

import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.manor.common.utils.str
import com.blankj.utilcode.util.SpanUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.drawable.DrawableCreator
import com.manor.common.utils.*
import com.manor.paradise.R
import com.manor.paradise.bean.Record
import java.math.BigDecimal


class PersonalStoresAdapter(layoutResId: Int, data: MutableList<Record>?) : BaseQuickAdapter<Record, BaseViewHolder>
(layoutResId, data) {



    override fun convert(helper: BaseViewHolder, item: Record) {
        val tvTime = helper.getView<TextView>(R.id.tv_time)
        val tvDeal = helper.getView<TextView>(R.id.tv_deal)
        val tvCustomer = helper.getView<TextView>(R.id.tv_customer)
        val tvState = helper.getView<TextView>(R.id.tv_state)
        val tvImg = helper.getView<TextView>(R.id.tv_img)
        val tvCloseShop = helper.getView<TextView>(R.id.tv_close_shop)
        val tvNeed = helper.getView<TextView>(R.id.tv_need)
        val tvExpend = helper.getView<TextView>(R.id.tv_expend)

        SpanUtils.with(helper.getView(R.id.tv_price))
                .appendLine("单价")
                .append(item.unit.scaleDown(2).toString() + "券")
                .setForegroundColor(Color.parseColor("#FF10DFF7"))
                .setFontSize(20, true)
                .create()

        if(item.saleType==1){
            tvCloseShop.str()
            tvImg.text = "换入嗨券"
            tvImg.background = DrawableCreator.Builder()
                    .setCornersRadius(DpUtil.dp2px(8).toFloat())
                    .setSolidColor(Color.parseColor("#FFE554A5"))
                    .build()
            val n = BigDecimal.ONE.subtract(item.serviceRate)
            tvCustomer.text = "需冻结：" + (item.sale.add(item.sold)).divideDown(n,4)+"米粒"



            tvNeed.text = "需换出："+(item.sale.add(item.sold).scaleDown(0))+"米粒"
            tvDeal.text = "已换出："+item.sold.scaleDown(0)+"米粒"
            tvExpend.text = "已获得："+item.sold.multiply(item.unit).scaleDown(2)+"嗨券"
        }else{
            tvImg.text = "换入米粒"
            tvImg.background = DrawableCreator.Builder()
                    .setCornersRadius(DpUtil.dp2px(8).toFloat())
                    .setSolidColor(Color.parseColor("#FF1AA7CB"))
                    .build()

            tvCustomer.text = "需冻结：" + (item.sale.add(item.sold)).multiply(item.unit).scaleDown(2)+"嗨券"
            tvNeed.text = "需换入："+(item.sale.add(item.sold).scaleDown(0))+"米粒"
            tvDeal.text = "已换入："+item.sold.scaleDown(0)+"米粒"
            tvExpend.text = "已消耗："+item.sold.multiply(item.unit).scaleDown(2)+"嗨券"
        }

        tvTime.text = "开店时间：" + item.createTime


        when (item.status) {
            1 -> {
                tvCloseShop.visibility = View.VISIBLE
                SpanUtils.with(tvState)
                        .appendLine("店铺排位")
                        .setForegroundColor(Color.parseColor("#FFFFFF"))
                        .append(item.rowNo)
                        .setForegroundColor(Color.parseColor("#FFDF62A7"))
                        .setFontSize(24, true)
                        .create()
            }
            2 -> {
                tvState.text = "已打烊"
                tvCloseShop.visibility = View.GONE
            }
            3 -> {
                tvState.text = "已搬迁"
                tvCloseShop.visibility = View.GONE
            }
        }

    }

}